/*
 * @(#) ArticleContoller.java 2018年2月8日 下午5:09:49
 *
 * Copyright 2018 CIMIP, Inc. All rights reserved.
 * H-VISIONS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */package cn.hc.share.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hc.share.entity.Answer;
import cn.hc.share.entity.Comment;
import cn.hc.share.service.CommentSaveException;
import cn.hc.share.service.CommentService;
import cn.hc.share.util.JsonResult;

@Controller
@RequestMapping("/comment")
public class CommentContoller extends AbstractController
{

	@Resource
	private CommentService commentService;

	/**
	 * 保存评论
	 * @param articleId
	 * @param userId
	 * @param commentContent
	 * @return
	 */
	@RequestMapping("/saveComment.do")
	@ResponseBody
	public Object saveComment(String articleId,String userId,String commentContent)
	{
		System.out.println("1:"+articleId+",2:"+userId+";3:"+commentContent);
		Comment comment = commentService.saveComment(articleId,userId,commentContent);
		return new JsonResult(comment);
	}
	@RequestMapping("/saveAnswer.do")
	@ResponseBody
	public Object saveAnswer(String userId,String commentId,String replyUserId,String answerContent)
	{
		System.out.println("1:"+userId+",2:"+commentId+";3:"+replyUserId+";4:"+answerContent);
		Answer answer= commentService.saveAnswer(userId,commentId,replyUserId,answerContent);
		return new JsonResult(answer);
	}
	@RequestMapping("/removeComments.do")
	@ResponseBody
	public Object removeComments(String id,String type)
	{
		int num = commentService.removeComments(id,type);
		Object obj=num;
		return new JsonResult(obj);
	}

	@RequestMapping("/getComment.do")
	@ResponseBody
	public Object getComment(String articleId)
	{
		List<Comment> comments = commentService.getComment(articleId);
		return new JsonResult(comments);
	}
	
	@ExceptionHandler(CommentSaveException.class)
	@ResponseBody
	public JsonResult handleCommentSave(CommentSaveException e)
	{
		e.printStackTrace();
		return new JsonResult(2, e);
	}

}









